package com.A1908.service.impl;

import com.A1908.dao.AttendPeopleInfoDao;
import com.A1908.dao.FeastInfoDao;
import com.A1908.dao.impl.AttendPeopleInfoDaoImpl;
import com.A1908.dao.impl.FeastInfoDaoImpl;
import com.A1908.entity.FeastInfo;
import com.A1908.entity.FeastInfoDataAnalysis;
import com.A1908.entity.PageEntity;
import com.A1908.entity.User;
import com.A1908.service.FeastInfoService;

import java.util.ArrayList;
import java.util.List;

public class FeastInfoServiceImpl implements FeastInfoService {
    FeastInfoDao infoDao = new FeastInfoDaoImpl();
    AttendPeopleInfoDao attendPeopleInfoDao = new AttendPeopleInfoDaoImpl();

    @Override
    public List<FeastInfo> findAllFeastInfo(User user) {
        return infoDao.getAllFeastInfo(user);
    }

    @Override
    public List<FeastInfo> findAllFeastInfo(User user, PageEntity pageEntity) {
        List<FeastInfo> list = infoDao.getAllFeastInfo(user, pageEntity);
        pageEntity.setTotalCount(infoDao.getCount(user));
        if (pageEntity.getTotalCount() % pageEntity.getPageSize() == 0) {
            pageEntity.setTotalPage(pageEntity.getTotalCount() / pageEntity.getPageSize());
        } else {
            pageEntity.setTotalPage((pageEntity.getTotalCount() / pageEntity.getPageSize()) + 1);
        }
        pageEntity.setInfo(list);
        return list;
    }

    @Override
    public int addFeastInfo(FeastInfo info) {
        return infoDao.addFeastInfo(info);
    }

    @Override
    public void findFeastInfoByName(FeastInfo feastInfo, PageEntity pageEntity) {
        List<FeastInfo> list = infoDao.getFeastInfoByName(feastInfo, pageEntity);
        pageEntity.setTotalCount(infoDao.getCountByName(feastInfo));
        if (pageEntity.getTotalCount() % pageEntity.getPageSize() == 0) {
            pageEntity.setTotalPage(pageEntity.getTotalCount() / pageEntity.getPageSize());
        } else {
            pageEntity.setTotalPage((pageEntity.getTotalCount() / pageEntity.getPageSize()) + 1);
        }
        pageEntity.setInfo(list);
    }

    @Override
    public int delFeastInfo(FeastInfo info, User user) {
        int attendPeople = attendPeopleInfoDao.delAttendPeopleByFeast(info);
        return infoDao.delFeastInfo(info, user);
    }

    public FeastInfoDataAnalysis getFeastAnalysis(User user) {
        FeastInfoDataAnalysis infoDataAnalysis = new FeastInfoDataAnalysis();

        FeastInfoDaoImpl feastInfoDao = new FeastInfoDaoImpl();

        infoDataAnalysis.setTotoInfo(feastInfoDao.getFeastAnalysis(user));
        infoDataAnalysis.setMaxCost(feastInfoDao.getFeastAnalysisMaxCost(user));
        infoDataAnalysis.setMaxGet(feastInfoDao.getFeastAnalysisMaxGet(user));
        infoDataAnalysis.setMinCost(feastInfoDao.getFeastAnalysisMinCost(user));
        infoDataAnalysis.setMinGet(feastInfoDao.getFeastAnalysisMinGet(user));
        return infoDataAnalysis;
    }

    @Override
    public int updateFeastInfo(FeastInfo info) {
        return infoDao.updateFeastInfo(info);
    }
}
